//
//  YBBuyWebViewController.m
//  GoodBuy
//
//  Created by Cyber on 15/5/14.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "YBBuyWebViewController.h"

@interface YBBuyWebViewController ()

@end

@implementation YBBuyWebViewController

-(void)dealloc {
    [_buyWebView release];
    [_titleLabel release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"url= %@", _webUrl);
    self.buyWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-104)];
    NSURL *url = [NSURL URLWithString:_webUrl];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_buyWebView loadRequest:request];
    [self.view addSubview:_buyWebView];
    
    
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 44)];
//    headView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:headView];
    UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
    dismissButton.frame = CGRectMake(0, 0, 44, 44);
//    dismissButton.backgroundColor = [UIColor blackColor];
    [dismissButton setImage:[UIImage imageNamed:@"iconfont-houtui (2)"] forState:UIControlStateNormal];
    dismissButton.center = CGPointMake(30, headView.frame.size.height/2);
    [dismissButton addTarget:self action:@selector(dismissAction:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:dismissButton];
    [headView release];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(dismissButton.frame.origin.x + 54, 0, [UIScreen mainScreen].bounds.size.width - dismissButton.frame.size.width - 30, 44)];
//    _titleLabel.backgroundColor = [UIColor redColor];
    _titleLabel.text = _titleStr;
    _titleLabel.textAlignment = UITextAlignmentCenter;
    _titleLabel.font = [UIFont systemFontOfSize:20];
    [headView addSubview:_titleLabel];
    [_titleLabel release];
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 30, [UIScreen mainScreen].bounds.size.width, 30)];
    [self.view addSubview:footView];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/8 - 15, 0, 30, 30);
//    backButton.backgroundColor = [UIColor blackColor];
    [backButton setImage:[UIImage imageNamed:@"iconfont-houtui"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:backButton];
    [footView release];
    
    UIButton *forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    forwardButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/8*3- 15, 0, 30, 30);
//    forwardButton.backgroundColor = [UIColor blackColor];
    [forwardButton setImage:[UIImage imageNamed:@"iconfont-qianjin"] forState:UIControlStateNormal];
    [forwardButton addTarget:self action:@selector(forwardAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:forwardButton];
    
    UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
    refreshButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/8*5- 15, 0, 30, 30);
//    refreshButton.backgroundColor = [UIColor blackColor];
    [refreshButton setImage:[UIImage imageNamed:@"iconfont-shuaxin"] forState:UIControlStateNormal];
    [refreshButton addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:refreshButton];
    
    UIButton *stopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    stopButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/8*7- 15, 0, 30, 30);
//    stopButton.backgroundColor = [UIColor blackColor];
    [stopButton setImage:[UIImage imageNamed:@"iconfont-icon"] forState:UIControlStateNormal];
    [stopButton addTarget:self action:@selector(stopAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:stopButton];
    
    
    
}

- (void)backAction {
    [_buyWebView goBack];
}

- (void)forwardAction {
    [_buyWebView goForward];
}

- (void)refreshAction {
    [_buyWebView reload];
}

- (void)stopAction {
    [_buyWebView stopLoading];
}

- (void)dismissAction:(UIButton *)button {
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    _titleLabel.text = _titleStr;
    [_titleLabel setText:titleStr];
    NSLog(@"titleStr = %@", _titleStr);
    [_titleLabel setTextColor:[UIColor blackColor]];
    [_titleLabel reloadInputViews];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
